//=======================================================
// 作者：KingSley
// 描述：通过DOTween的DOBlendable实现作用于Cube的多动画同步播放
//=======================================================
using UnityEngine;
using System.Collections;
using DG.Tweening;

namespace Babybus.Uno
{
    public class MainCameraDotweenUseOnCube : MonoBehaviour
    {
        private void Start()
        {
            // SetEase设置运动模式（运动速度）
            transform.DOBlendableMoveBy(new Vector3(3, 3, 0), 3).SetEase(Ease.InOutCubic);
            transform.DOBlendableMoveBy(new Vector3(-3, 0, 0), 1f).SetLoops(3, LoopType.Yoyo);
            transform.DOBlendableLocalRotateBy(new Vector3(0, 180, 0), 0.5f).SetLoops(6, LoopType.Yoyo);
            // OnComplete在动画结束后执行
            transform.DOBlendableScaleBy(new Vector3(2, 2, 2), 1f).SetLoops(3, LoopType.Yoyo).OnComplete(OnComplete);
        }

        /// <summary>
        /// 在调用该函数动画播放结束后执行，倒放一次所有动画
        /// </summary>
        private void OnComplete()
        {
            // PlayBackwards反向播放动画
            transform.DOBlendableScaleBy(new Vector3(2, 2, 2), 1f).SetLoops(3, LoopType.Yoyo).PlayBackwards();
            transform.DOBlendableLocalRotateBy(new Vector3(0, 180, 0), 0.5f).SetLoops(6, LoopType.Yoyo).PlayBackwards();
            transform.DOBlendableMoveBy(new Vector3(-3, 0, 0), 1f).SetLoops(3, LoopType.Yoyo).PlayBackwards();
            transform.DOBlendableMoveBy(new Vector3(3, 3, 0), 3).SetEase(Ease.InOutCubic).PlayBackwards();
        }
    }
}
